<!doctype html>
<html lang="en">
  <head>
  <meta charset="UTF-8">
  <title>Login</title>   
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="description" content="Ams system login">
	<link rel="stylesheet" href="js/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" href="js/easyui/themes/icon.css">
	<link rel="stylesheet" href="js/easyui/themes/color.css">
	<link rel="stylesheet" href="css/index.css" />
	<link rel="stylesheet" href="css/index-ui.css" />
	<script type="text/javascript" src="js2/jquery.min.js"></script>
  <script type="text/javascript" src="js2/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="js2/loginCookies.js"></script>
  <script type="text/javascript" src="js/ams.util.js"></script>
	<script type="text/javascript" src="js/webapi.js"></script>
  </head>
	<body>
		<div data-options="region:'north'" class="index-top">
			<div class="index-top-content">
				<div class="index-top-logo">
					<p><img src="img/logo.png" alt="" /></p>
				</div>
				<span style="float:left;font-size:22px;color:#ffffff;margin:20px">Automated Monitoring System</span>
			</div>
		</div>
		<div style="float:center;margin:auto;width:1000px;padding-top: 100px;padding-right: 100px">
			<div style="float:left">
				<img src="images/homepage.jpg" alt="" />
			</div>
			<div class="easyui-panel" title="" style="float:left;width:100%;max-width:370px;padding:30px 60px;margin-top: 135px;">
				<form id="ff" method="post">
					<div style="margin-bottom:20px">
						<input class="easyui-textbox" name="Username" prompt="Username" iconWidth="28" style="width:100%;height:34px;padding:10px;" 
							data-options="required:true">
					</div>
					<div style="margin-bottom:20px">
						<input class="easyui-passwordbox" name="Password" prompt="Password" iconWidth="28" style="width:100%;height:34px;padding:10px"
							data-options="required:true">
					</div>
				</form>
				<div style="text-align:center;padding:5px 0">
					<a href="javascript:void(0)" class="easyui-linkbutton c4" onclick="doLogin()" style="width:100%">Sign in</a>
				</div>
			</div>
		</div>
	<script type="text/javascript">
	function doLogin()
	{
		var user_name = $("input[name='Username']").val()
		var user_pwd = $("input[name='Password']").val()
		if (user_name == "" || user_pwd == "") {
			return
		} else {
      if (ams_is_sim_mode()) {
				 window.location.href = "main.html"
			} 
			else {
				$.ajax({
							type: 'POST',
							contentType: 'application/json',
							url: getWebServiceUrl("login"),
							data:JSON.stringify({
								"cmd":0,
								"user":$("input[name='Username']").val(),
								"pw":$("input[name='Password']").val(),
							}),
							dataType: 'json',
							success: function (json_data) {
								var res = JSON.parse(json_data.d).result;
								if(res == "0"){
									SetCookie('ams_user_name', JSON.parse(json_data.d).user);
									SetCookie('ams_user_level', JSON.parse(json_data.d).level);
									$("#login").dialog("close");
									window.location.href = "main.html";
							}else if(res == "1"){
								$.messager.alert("Error", "Username does not exist.", "error");
							}else if(res == "2"){
								$.messager.alert("Error", "Password error.", "error");
								}else{
									$.messager.alert("Error", "Login failed.", "error");
								}
							},
							error: function (response) {
								//alert(errorThrown.message);
								alert('Error: ' + response.responseText)
							}
						});
			}
		}
	}
	</script>
  </body>
</html>